﻿using System;

namespace S7CommPlusDriver.ClientApi
{
    public class Helper
    {
        public static PlcTag CreatePlcTag(string name, ItemAddress address, Softdatatype softdatatype)
        {
            switch (softdatatype)
            {
                case Softdatatype.BOOL:
                    return new PlcTagBool(name, address, softdatatype);
                case Softdatatype.BYTE:
                    return new PlcTagByte(name, address, softdatatype);
                case Softdatatype.CHAR:
                    return new PlcTagChar(name, address, softdatatype);
                case Softdatatype.WORD:
                    return new PlcTagWord(name, address, softdatatype);
                case Softdatatype.INT:
                    return new PlcTagInt(name, address, softdatatype);
                case Softdatatype.DWORD:
                    return new PlcTagDWord(name, address, softdatatype);
                case Softdatatype.DINT:
                    return new PlcTagDInt(name, address, softdatatype);
                case Softdatatype.REAL:
                    return new PlcTagReal(name, address, softdatatype);
                case Softdatatype.DATE:
                    return new PlcTagDate(name, address, softdatatype);
                case Softdatatype.TIMEOFDAY:
                    return new PlcTagTimeOfDay(name, address, softdatatype);
                case Softdatatype.TIME:
                    return new PlcTagTime(name, address, softdatatype);
                case Softdatatype.S5TIME:
                    return new PlcTagS5Time(name, address, softdatatype);
                case Softdatatype.DATEANDTIME:
                    return new PlcTagDateAndTime(name, address, softdatatype);
                case Softdatatype.STRING:
                    return new PlcTagString(name, address, softdatatype);
                case Softdatatype.POINTER:
                    return new PlcTagPointer(name, address, softdatatype);
                case Softdatatype.ANY:
                    return new PlcTagAny(name, address, softdatatype);
                case Softdatatype.BLOCKFB:
                    return new PlcTagUInt(name, address, softdatatype);
                case Softdatatype.BLOCKFC:
                    return new PlcTagUInt(name, address, softdatatype);
                case Softdatatype.COUNTER:
                    return new PlcTagUInt(name, address, softdatatype);
                case Softdatatype.TIMER:
                    return new PlcTagUInt(name, address, softdatatype);
                case Softdatatype.S7COMMP_SOFTDATATYPE_BBOOL:
                    return new PlcTagBool(name, address, softdatatype);
                case Softdatatype.LREAL:
                    return new PlcTagLReal(name, address, softdatatype);
                case Softdatatype.ULINT:
                    return new PlcTagULInt(name, address, softdatatype);
                case Softdatatype.LINT:
                    return new PlcTagLInt(name, address, softdatatype);
                case Softdatatype.LWORD:
                    return new PlcTagLWord(name, address, softdatatype);
                case Softdatatype.USINT:
                    return new PlcTagUSInt(name, address, softdatatype);
                case Softdatatype.UINT:
                    return new PlcTagUInt(name, address, softdatatype);
                case Softdatatype.UDINT:
                    return new PlcTagUDInt(name, address, softdatatype);
                case Softdatatype.SINT:
                    return new PlcTagSInt(name, address, softdatatype);
                case Softdatatype.WCHAR:
                    return new PlcTagWChar(name, address, softdatatype);
                case Softdatatype.WSTRING:
                    return new PlcTagWString(name, address, softdatatype);
                //case Softdatatype.S7COMMP_SOFTDATATYPE_VARIANT:
                //-> Variant isn't added int the instance-db as a variable!
                case Softdatatype.LTIME:
                    return new PlcTagLTime(name, address, softdatatype);
                case Softdatatype.S7COMMP_SOFTDATATYPE_LTOD:
                    return new PlcTagLTOD(name, address, softdatatype);
                case Softdatatype.S7COMMP_SOFTDATATYPE_LDT:
                    return new PlcTagLDT(name, address, softdatatype);
                case Softdatatype.DTL:
                    return new PlcTagDTL(name, address, softdatatype);
                case Softdatatype.REMOTE:
                    return new PlcTagAny(name, address, softdatatype);
                case Softdatatype.AOM_IDENT:
                    return new PlcTagDWord(name, address, softdatatype);
                case Softdatatype.S7COMMP_SOFTDATATYPE_EVENTANY:
                    return new PlcTagDWord(name, address, softdatatype);
                case Softdatatype.S7COMMP_SOFTDATATYPE_EVENTATT:
                    return new PlcTagDWord(name, address, softdatatype);
                case Softdatatype.S7COMMP_SOFTDATATYPE_FOLDER:
                    // Softdatatype 132: This type is only used as parameter for internal SFBs (e.g. AID input parameter)
                    // Length of value (4 byte) calculated from the offsetinfo byte addresses.
                    return new PlcTagDWord(name, address, softdatatype);
                case Softdatatype.S7COMMP_SOFTDATATYPE_AOMLINK:
                    return new PlcTagDWord(name, address, softdatatype);

                case Softdatatype.S7COMMP_SOFTDATATYPE_HWANY:
                    return new PlcTagWord(name, address, softdatatype);

                case Softdatatype.S7COMMP_SOFTDATATYPE_HWIOSYSTEM:
                    return new PlcTagWord(name, address, softdatatype);
                case Softdatatype.S7COMMP_SOFTDATATYPE_HWDPMASTER:
                    return new PlcTagWord(name, address, softdatatype);
                case Softdatatype.S7COMMP_SOFTDATATYPE_HWDEVICE:
                    return new PlcTagWord(name, address, softdatatype);
                case Softdatatype.S7COMMP_SOFTDATATYPE_HWDPSLAVE:
                    return new PlcTagWord(name, address, softdatatype);
                case Softdatatype.S7COMMP_SOFTDATATYPE_HWIO:
                    return new PlcTagWord(name, address, softdatatype);
                case Softdatatype.S7COMMP_SOFTDATATYPE_HWMODULE:
                    return new PlcTagWord(name, address, softdatatype);
                case Softdatatype.S7COMMP_SOFTDATATYPE_HWSUBMODULE:
                    return new PlcTagWord(name, address, softdatatype);
                case Softdatatype.S7COMMP_SOFTDATATYPE_HWHSC:
                    return new PlcTagWord(name, address, softdatatype);
                case Softdatatype.S7COMMP_SOFTDATATYPE_HWPWM:
                    return new PlcTagWord(name, address, softdatatype);
                case Softdatatype.S7COMMP_SOFTDATATYPE_HWPTO:
                    return new PlcTagWord(name, address, softdatatype);
                case Softdatatype.S7COMMP_SOFTDATATYPE_HWINTERFACE:
                    return new PlcTagWord(name, address, softdatatype);
                case Softdatatype.S7COMMP_SOFTDATATYPE_HWIEPORT:
                    return new PlcTagWord(name, address, softdatatype);

                case Softdatatype.S7COMMP_SOFTDATATYPE_OBANY:
                    return new PlcTagInt(name, address, softdatatype);
                case Softdatatype.S7COMMP_SOFTDATATYPE_OBDELAY:
                    return new PlcTagInt(name, address, softdatatype);
                case Softdatatype.S7COMMP_SOFTDATATYPE_OBTOD:
                    return new PlcTagInt(name, address, softdatatype);
                case Softdatatype.S7COMMP_SOFTDATATYPE_OBCYCLIC:
                    return new PlcTagInt(name, address, softdatatype);
                case Softdatatype.S7COMMP_SOFTDATATYPE_OBATT:
                    return new PlcTagInt(name, address, softdatatype);

                case Softdatatype.S7COMMP_SOFTDATATYPE_CONNANY:
                    return new PlcTagWord(name, address, softdatatype);
                case Softdatatype.S7COMMP_SOFTDATATYPE_CONNPRG:
                    return new PlcTagWord(name, address, softdatatype);
                case Softdatatype.S7COMMP_SOFTDATATYPE_CONNOUC:
                    return new PlcTagWord(name, address, softdatatype);
                case Softdatatype.S7COMMP_SOFTDATATYPE_CONNRID:
                    return new PlcTagDWord(name, address, softdatatype);

                case Softdatatype.S7COMMP_SOFTDATATYPE_PORT:
                    return new PlcTagUInt(name, address, softdatatype);
                case Softdatatype.S7COMMP_SOFTDATATYPE_RTM:
                    return new PlcTagUInt(name, address, softdatatype);
                case Softdatatype.S7COMMP_SOFTDATATYPE_PIP:
                    return new PlcTagUInt(name, address, softdatatype);

                case Softdatatype.S7COMMP_SOFTDATATYPE_OBPCYCLE:
                    return new PlcTagInt(name, address, softdatatype);
                case Softdatatype.S7COMMP_SOFTDATATYPE_OBHWINT:
                    return new PlcTagInt(name, address, softdatatype);

                case Softdatatype.S7COMMP_SOFTDATATYPE_OBDIAG:
                    return new PlcTagInt(name, address, softdatatype);
                case Softdatatype.S7COMMP_SOFTDATATYPE_OBTIMEERROR:
                    return new PlcTagInt(name, address, softdatatype);
                case Softdatatype.S7COMMP_SOFTDATATYPE_OBSTARTUP:
                    return new PlcTagInt(name, address, softdatatype);

                case Softdatatype.DBANY:
                    return new PlcTagUInt(name, address, softdatatype);
                case Softdatatype.DB_WWW:
                    return new PlcTagUInt(name, address, softdatatype);
                case Softdatatype.DB_DYN:
                    return new PlcTagUInt(name, address, softdatatype);

                default:
                    Console.WriteLine("ERROR: Unknown softdatatype=" + softdatatype.ToString() + " for variable= " + name);
                    return null;
            }
        }
    }
}
